package service.impl;

import dao.CategoryDao;
import dao.impl.CategoryDaoImpl;
import pojo.Category;
import pojo.Knowledge;
import pojo.vo.Message;
import service.CategoryService;

import java.util.List;

/**
 * @author wq3stone
 */
public class CategoryServiceImpl implements CategoryService {
    CategoryDao categoryDao = new CategoryDaoImpl();


    @Override
    public Message deleteCategory(int code) {
        Message message = new Message();
        try {
            categoryDao.delete(code);
            message.setCode(0);
            message.setMsg("删除分类成功");
            message.setObj(null);
        } catch (Exception e){
            e.printStackTrace();
            message.setCode(1);
            message.setMsg("删除分类失败");
            message.setObj(null);
            e.printStackTrace();
        }
        return message;
    }

    @Override
    public Message updateCategory(Category category) {
        Message message = new Message();
        try{
            categoryDao.update(category);
            message.setCode(0);
            message.setMsg("更新成功");
            message.setObj(category);
        } catch (Exception e){
            message.setCode(1);
            message.setMsg("更新失败");
            message.setObj(category);
            e.printStackTrace();
        }
        return message;
    }

    @Override
    public Message queryFirstCategory(int uid) {
        Message message = new Message();
        try{
            List<Category> list = categoryDao.queryFirstCategory(uid);
            message.setCode(0);
            message.setMsg("查询成功");
            message.setObj(list);
        } catch (Exception e){
            message.setCode(1);
            message.setMsg("查询失败");
            message.setObj(null);
            e.printStackTrace();
        }
        return message;
    }

    @Override
    public Message querySecondCategory(int pcode) {
        Message message = new Message();
        try{
            List<Category> list = categoryDao.querySecondCategory(pcode);
            message.setCode(0);
            message.setMsg("查询成功");
            message.setObj(list);
        } catch (Exception e){
            message.setCode(1);
            message.setMsg("查询失败");
            message.setObj(null);
            e.printStackTrace();
        }
        return message;
    }

}
